<?php
include_once __DIR__ . '/../BaseShell.php';
$use_pass = Lib_Repair_Config::getConfig('use_pass',0);
if($use_pass == 'ZaiRui'){
    $env = getenv('RUNTIME_ENVIROMENT') ? getenv('RUNTIME_ENVIROMENT') : (defined('SHELL_VARIABLE') ? SHELL_VARIABLE : '');
    $env = empty($env) ? 'rls' : $env;
    $config = require_once LIBRARY_DIR . '/Conf/' . $env . '/repair.php';
    if(!isset($config['MiddleNumber'])){
        echo 'config no find'.PHP_EOL;
        return false;
    }
    foreach ($config['MiddleNumber'] as $telx){
        $surplus_time = Lib_Redis_String::ttl("bind_" . $telx);
        if($surplus_time > 0 && $surplus_time < 3540){
            $bind = Lib_Redis_String::get("bind_" . $telx);
            //绑定超过1分自动解绑
            if ($bind) {
                $result = Lib_Repair_Implement_ZaiRui::getInstance()->unbinding(json_decode($bind, true));
                Lib_Redis_String::del("bind_".$telx);
                Func_Log::write('repair',   $telx . ' outo unbind',"responsedata: ". json_encode($result));
            }
        }
    }
}else{
    $telX_set_key = Lib_Repair_Adapter_LianTong::$telX_set_key;
    $bindTel = Lib_Redis_Set::sMembers($telX_set_key);
    if(!empty($bindTel)){
        foreach ($bindTel as $telx) {
            $surplus_time = Lib_Redis_String::ttl("bind_" . $telx);
            if($surplus_time > 0 && $surplus_time < 3540){
                $bind = Lib_Redis_String::get("bind_" . $telx);
                //绑定超过1分自动解绑
                if ($bind) {
                    $result = Lib_Repair_Implement_LianTong::getInstance()->unbinding(json_decode($bind, true));
                    Lib_Redis_String::del("bind_".$telx);
                    Lib_Redis_Set::sRem($telX_set_key,$telx);
                    Func_Log::write('repair',   $telx . ' outo unbind',"responsedata: ". json_encode($result));
                }else{
                    Lib_Redis_Set::sRem($telX_set_key,$telx);
                }
            }elseif($surplus_time == -2){
                Lib_Redis_Set::sRem($telX_set_key,$telx);
            }
        }
    }
}
